

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libcarai.h"

int main(){
	char *str = NULL, *straux = NULL, *final = NULL ;
	int num, i;
	unsigned char ch;
	FILE *fp = NULL;
	fp = fopen("arq.bin", "wb");

	straux = (char*)malloc(sizeof(char) * 9);
	str = (char*)malloc(sizeof(char) * 25);
	strcpy(str, "101010000000110111100000");
	
	str[24] = '\0';
	printf("straux: %s\n", str);
	
	strncpy(straux, str, 8);
	straux[8] = '\0';
	ch =  binToDecPure(straux);
	printf("(int)ch1: %d\n", ch);
	fwrite(&ch, sizeof(char), 1, fp);

	strncpy(straux, &str[8], 8);
	straux[8] = '\0';
	ch =  binToDecPure(straux);
	printf("(int)ch2: %d\n", ch);
	fwrite(&ch, sizeof(char), 1, fp);
	
	strncpy(straux, &str[16], 8);
	straux[8] = '\0';
	ch =  binToDecPure(straux);
	printf("(int)ch3: %d\n", ch);
	fwrite(&ch, sizeof(char), 1, fp);

//	free(str);	
	fclose(fp);
		
	fp = fopen("arq.bin", "rb");
	final = (char*) malloc (sizeof(char)*30);
	final[0] = '\0';

	fread(&ch, sizeof(unsigned char), 1, fp);
	printf("(int)ch1: %d\n", ch, ch);
	strcat(final, decToBinPure((int) ch));
	
	fread(&ch, sizeof(unsigned char), 1, fp);
	printf("(int)ch2: %d\n", ch, ch);
	strcat(final, decToBinPure((int) ch));
	
	fread(&ch, sizeof(unsigned char), 1, fp);
	printf("(int)ch3: %d\n", ch, ch);
	strcat(final, decToBinPure((int) ch));
	fclose(fp);
	printf("\n\nstraux:\t%s\n", str);
	printf("final:\t%s\n", final);

	for(i = -130; i < 130; i++){
		printf("i: %d, bits: %d\n", i, numberOfBits(i));
	}
	return 0;	
}

